<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="表名称">
              <a-input placeholder="请输入表名称" v-model="queryParam.fdTableName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="状态">
              <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.fdStatus" dictCode="hadoop_hdflag"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator" >
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <!-- 字符串超长截取省略号显示-->
        <span slot="fdWhere" slot-scope="text">
          <j-ellipsis :value="text" :length="8" />
        </span>
        <span slot="action" slot-scope="text, record" >
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a href="javascript:;" @click="fieldShow(record.fdTableId)">字段展示</a>
          <a-divider type="vertical"/>
           <a href="javascript:;" @click="handleDetail(record.fdTableId)">详情</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->
    <show-fieldinfo-modal ref="showFieldinfoModal"></show-fieldinfo-modal>
    <add-tableinfo-modal ref="addTableinfoModal" @ok="modalFormOk"></add-tableinfo-modal>
    <sys-tableinfo-modal ref="sysTableinfoModal"></sys-tableinfo-modal>

    <!-- 表单区域 -->
    <AutosscDetail-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>
  import ShowFieldinfoModal from './modules/ShowFieldinfoModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'
  import AutosscDetailModal from './modules/AutosscDetailModal'
  import AddTableinfoModal from './modules/AddTableinfoModal'
  import JEllipsis from "@/components/jeecg/JEllipsis";
  import SysTableinfoModal from '../../modules/meta/modules/SysTableinfoModal'
  export default {
    name: 'AutosscDetailList',
    mixins: [JeecgListMixin],
    components: {
      SysTableinfoModal,
      JEllipsis,
      AutosscDetailModal,
      ShowFieldinfoModal,
      AddTableinfoModal
    },
    data() {
      return {

        description: '信息',
        // 表头
        columns: [
       /*   {
            title: '表id',
            align: 'center',
            dataIndex: 'fdTableId'
          },*/
          {
            title: '表名称',
            align: 'center',
            dataIndex: 'fdTableId_dictText'
          },
          {
            title: '自定义条件',
            align: 'center',
            dataIndex: 'fdWhere',
            scopedSlots: {customRender: 'fdWhere'},
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'fdStatus_dictText'
          },
          {
            title: '操作',
            key: 'operation',
            align: 'center',
            width: 230,
            scopedSlots: { customRender: 'action' }
          }],
        url: {

          list: '/rule/autossc/listAutosscDetailByMainId',
          delete: '/rule/autossc/deleteAutosscDetail',
          deleteBatch: '/rule/autossc/deleteBatchAutosscDetail',
        }
      }
    },
    created: function() {
      this.queryParamConfig = { 'fdTableId': 'like' }
    },
    methods: {
      loadData(arg) {
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams()
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;

          } else {
            this.dataSource = null
          }
          this.loading = false
        })
      },
      getMain(fdSscid) {
        this.queryParam.fdSscid = fdSscid
        this.loadData(1)
      },
      handleAdd: function() {
        if (this.queryParam.fdSscid == undefined) {
          alert('请选择自动脱敏后点击')
        } else {
          this.$refs.addTableinfoModal.edit((this.queryParam.fdSscid))
          this.$refs.addTableinfoModal.title = '添加自动脱敏详情表'
        }
      },
      fieldShow(fdTableId){
        this.$refs.showFieldinfoModal.edit(fdTableId);
        this.$refs.showFieldinfoModal.title = "字段展示";
      },
      handleDetail(fdTableId){
      this.$refs.sysTableinfoModal.etails(fdTableId);
      this.$refs.sysTableinfoModal.title = "详情";
  },
      searchQuery: function() {
          this.selectedRowKeys = []
          this.selectionRows = []
          this.loadData()
        },
      searchReset: function() {
        this.queryParam = { fdSscid: this.queryParam.fdSscid }
        this.loadData(1)
      }
      },


  }
</script>
<style scoped>
  .ant-card {
    margin-left: -30px;
    margin-right: -30px;
  }
</style>
